package com.schoolpro.controller;


import com.schoolpro.pojo.DTO.CategoryAddDTO;
import com.schoolpro.pojo.DTO.CategoryUpdateDTO;
import com.schoolpro.pojo.Request;
import com.schoolpro.pojo.Result;
import com.schoolpro.pojo.VO.CategoryWithPropertyVO;
import com.schoolpro.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author : Hinton
* @时间 : 1月 22 22:12
*/

@Slf4j
@RestController
@RequestMapping("/category")
@Tag(name = "类目管理")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    /**
     * 添加类目
     * @param categoryAddRequest
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "添加类目")
    public Result<Object> addCategory(@RequestBody Request<CategoryAddDTO> categoryAddRequest){
        categoryService.addCategory(categoryAddRequest.getParam());
        log.info("添加分类{}", categoryAddRequest.getParam());
        return Result.success();
    }

    @DeleteMapping
    public Result<Object> deleteCategory(@RequestParam List<Integer> ids){
        categoryService.deleteCategory(ids);
        return Result.success();
    }

    /**
     * 修改类目名称
     * @param categoryUpdateDTO
     * @return
     */
    @PutMapping
    @Operation(summary = "修改类目名称")
    public Result<Object> updateCategory(@RequestBody Request<CategoryUpdateDTO> categoryUpdateDTO){
        categoryService.updateCategory(categoryUpdateDTO.getParam());
        return Result.success();
    }

    /**
     * 获取类目属性
     * @param id
     * @return
     */
    @GetMapping("/property/{id}")
    @Operation(summary = "获取类目属性")
    public Result<CategoryWithPropertyVO> getCategoryProperty(@PathVariable Integer id){
        return Result.success(categoryService.getCategoryWithProperty(id));
    }




}
